(function() {

    "use strict";

    describe("CoreTestCase", function() {
        it("should modules be started and rendered after init", function () {
            var core = new nw.Core();
            core._startModules = window.stubFn();
            core._renderModules = window.stubFn();
            core.init(new nw.Sandbox(core));
            expect(core._startModules.called).to.be.ok();
            expect(core._renderModules.called).to.be.ok();
        });

      	it("should be initiated the current view name", function () {
			var core = new nw.Core();
			expect(core.currentViewName).to.eql(nw.enums.views.v1);
		});
    });

    describe("CoreModulesTestCase", function() {

        beforeEach(function() {
            this.core = new nw.Core();
        });

        afterEach(function() {
        });

        it("should load module", function() {
            var module = function(){};
            this.core.loadModule("module1", module);
            expect(this.core.getModule("module1").constructor).to.eql(module);
            expect(this.core.getModule("module3")).to.eql(undefined);
        });

        it("should load equal modules", function() {
            var module = function(){};
            this.core.loadModule("module1", module);
            this.core.loadModule("module2", module);

            expect(this.core.getModule("module1").constructor).to.eql(module);
            expect(this.core.getModule("module2").constructor).to.eql(module);
        });

        it("should start modules", function() {
            this.core.loadModule("module1", function(){
                return {init: window.stubFn()};
            });
            this.core.loadModule("module2", function(){
                return {init: window.stubFn()};
            });
            this.core._startModules();
            expect(this.core.getModule("module1").instance.init.called).to.be.ok();
            expect(this.core.getModule("module2").instance.init.called).to.be.ok();
        });

        it("should render modules", function() {
            this.core.loadModule("module1", function(){
                return {init: window.stubFn(), render: window.stubFn()};
            });
            this.core.loadModule("module2", function(){
                return {init: window.stubFn(), render: window.stubFn()};
            });
            this.core._startModules();
            this.core._renderModules();
            expect(this.core.getModule("module1").instance.render.called).to.be.ok();
            expect(this.core.getModule("module2").instance.render.called).to.be.ok();
        });

        it("should go to the View", function() {
            this.core.loadModule(nw.enums.views.v1, function(){
                return {init: window.stubFn(), hide: window.stubFn()};
            });
            this.core.loadModule(nw.enums.views.v2, function(){
                return {init: window.stubFn(), show: window.stubFn()};
            });
            this.core._startModules();
            this.core.goView(nw.enums.views.v2);

            expect(this.core.getModule(nw.enums.views.v1).instance.hide.called).to.be.ok();
            expect(this.core.getModule(nw.enums.views.v2).instance.show.called).to.be.ok();
        });
    });

    describe("CorePluginsTestCase", function() {
        it("test should load plugin", function () {
            var core = new nw.Core();
            var plugin = {};
            core.loadPlugin("plugin1", plugin);

            expect(core.getPlugin("plugin1")).to.eql(plugin);
            expect(core.getPlugin("plugin2")).to.eql(undefined);
        });
    });
}());